import {Route, Switch} from "react-router-dom";
import React from "react";
import routes from '../route/RouteConfig'
import WrappedComponent from './without'

class RouteComponent extends React.Component {
    //组件被销毁之前重写setState方法 不对状态做任何改变
    componentWillUnmount(){
        this.setState = () => {return};
    }
    render() {
        const { routes } = this.props;
        console.log(routes)
        return (
            <div>
                <WrappedComponent wrappedComponentRef={c => this.component = c}/>
                <Switch>
                    {routes.map((route, i) => {
                        return <RouteWithSubRoutes key={i} {...route} />
                    })}
                </Switch>
            </div>
        );
    }
}
RouteComponent.defaultProps = {
    routes: routes
};
const RouteWithSubRoutes = route => {
    return (
       
        <Route
            path={route.path}
            render={props => {
                return <route.component {...props} children={route.children} />
            }}
        />
    )
};

export default RouteComponent